#include "stm32f4xx.h"                  // Device header



void delay_us(uint32_t xus){
	//SysTick->LOAD = 168 * xus;				//设置定时器重装值
	volatile uint32_t sta = SysTick->VAL;					//清空当前计数值
	//SysTick->CTRL = 0x05;				//设置时钟源为HCLK，启动定时器
	
	while(1){
		// down counter
		if(SysTick->VAL <= sta && (sta - SysTick->VAL)>=168*xus)
			break;
		if(SysTick->VAL > sta && (0xffffff-SysTick->VAL)+sta>=168*xus)
			break;
	}
	//SysTick->CTRL = 0x04;				//关闭定时器
}

void delay_ms(uint32_t xms){
	while(xms--){
		delay_us(1000);
	}
}
/**
  * @brief  秒级延时
  * @param  xs 延时时长，范围：0~4294967295
  * @retval 无
  */
void delay_s(uint32_t xs)
{
	while(xs--)
	{
		delay_ms(1000);
	}
} 
